package com.usermanage.Mapping;

import com.usermanage.beanParam.GroupBean;
import com.usermanage.beanParam.GroupMemberBean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by  on 2018/9/3
 */
@Repository("groupMemberMapping")
public interface GroupMemberMapping extends JpaRepository<GroupMemberBean, Integer> {

    /**
     * 验证该用户是否在该组中
     * @param groupId
     * @param topGroupId
     * @param userId
     * @return
     */
    @Query(value = "SELECT COUNT(1) FROM u_group_member where group_id =:groupId AND top_group_id =:topGroupId AND user_id =:userId",nativeQuery = true)
    int isExistGroupMember(@Param("groupId") String groupId,@Param("topGroupId") String topGroupId,@Param("userId") String userId);

    @Query(value = "SELECT group_id from u_group_member WHERE user_id = :userId AND company_id = :companyId",nativeQuery = true)
    List<Integer> findUserGroupId(@Param("userId") String userId,@Param("companyId") String companyId);
}
